import 'package:flutter/material.dart';
import 'package:weixinclone/Constants.dart' show AppStyles;
import 'package:weixinclone/Constants.dart' show AppColors;
import 'package:weixinclone/Constants.dart' show Constants;
import 'package:weixinclone/Constants.dart' show Contants;
import 'package:weixinclone/bean/ConversionBean.dart';

class ConveriosnItem extends StatelessWidget {
  ConversationBean _conversionBean;

  ConveriosnItem(this._conversionBean);

  @override
  Widget build(BuildContext context) {
    Widget avater;
    Widget avaterContainer;
    if (_conversionBean.url.indexOf("https") == 0) {
      avater = Image.network(
        _conversionBean.url,
        width: Constants.ConversationAvatarSize,
        height: Constants.ConversationAvatarSize,
      );
    } else {
      avater = Image.asset(
        _conversionBean.url,
        width: Constants.ConversationAvatarSize,
        height: Constants.ConversationAvatarSize,
      );
    }

    if (_conversionBean.unreadMsgCount > 0) {
      Widget unReadMsgCountContainer = Container(
        width: Constants.UnReadMsgNotifyDotSize,
        height: Constants.UnReadMsgNotifyDotSize,
        decoration: BoxDecoration(
            color: Color(AppColors.NotifyDotBg),
            borderRadius:
                BorderRadius.circular(Constants.UnReadMsgNotifyDotSize / 2)),
        alignment: Alignment.center,
        child: Text(
          _conversionBean.unreadMsgCount.toString(),
          style: AppStyles.UnreadMsgCountDotStyle,
        ),
      );

      avaterContainer = Stack(
        overflow: Overflow.visible,
        children: <Widget>[
          avater,
          Positioned(
            child: unReadMsgCountContainer,
            right: -6.0,
            top: -6.0,
          )
        ],
      );
    } else {
      avaterContainer = avater;
    }

    var _rightArea = <Widget>[
      Text(
        _conversionBean.updateAt,
        style: AppStyles.DesStyle,
      ),
      SizedBox(height: 10.0,)
    ];

    var iconMute;
    if (_conversionBean.isMute) {
      iconMute = Icon(IconData(0xe755, fontFamily: Contants.IconFontFamily),
          size: Constants.ConversationMuteIconSize,
          color: Color(AppColors.ConversationMuteIcon));
    } else {
      iconMute = Icon(IconData(0xe755, fontFamily: Contants.IconFontFamily),
          size: Constants.ConversationMuteIconSize, color: Colors.transparent);
    }

    _rightArea.add(iconMute);

    return Container(
        padding: EdgeInsets.all(10.0),
        decoration: BoxDecoration(
            color: Color(AppColors.ConversationItemBg),
            border: Border(
                bottom: BorderSide(
                    color: Color(AppColors.DividerColor),
                    width: Constants.DividerWidth))),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            avaterContainer,
            Container(width: 16),
            Expanded(
                child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  _conversionBean.title,
                  style: AppStyles.TitleStyle,
                ),
                Text(
                  _conversionBean.desc,
                  style: AppStyles.DesStyle,
                )
              ],
            )),
            Column(children: _rightArea),
          ],
        ));
  }
}
